<?php 
Class sysController extends appController
{
	public function file()
	{
	
		$file=current($_FILES);
		$result=array('error'=>0,'url'=>$file['name']);
		
		$thumb_url=Model('image')->upload_image($file, 'sys/'.date('Ym'));
		$result['url']=$thumb_url;
	
		$result['message']='';
		print_r(json_encode($result));
		exit();
	}
	
	public function website()
	{
		$tpl_list=$this->getTpl();
		$setting=Model('sys')->getSetting();
		$this->assign('ur_here','>站点信息');
		$this->assign('tpl_list',$tpl_list);
		$this->assign('setting',$setting);
		$this->display('website.html');
		
	}
	private function make_index()
	{
		$static = new StaticPage;
		$time=60;
		$saveDir=ROOT_PATH;
		$activePage="http://".$_SERVER['HTTP_HOST']."/index.php";
		
		$fileName=$static->getPageName(basename($activePage),'html');
		$flag=$static->reMakeCondition($saveDir.'/'.$fileName,$time);
		if(!$flag)
		{
			
		}
		$static->makeStaticPage($activePage,'html',$saveDir);
		
	}
	public function db()
	{
		$sql_list=Model('sys')->get_sql_list();
		
		$this->assign('sql_list',$sql_list);
		$this->display('database.html');
	}
	public function delsql()
	{
		$file_name = empty($_GET['file_name']) ? '': trim($_GET['file_name']);
		$filename=TEMP_PATH. '/sqldata/'.$file_name;
		$result=array('error'=>1,'content'=>Lang('INVALID_OPERATION'));
		if(is_file($filename))
		{
			@unlink($filename);
			$result['error']=0;
			$result['content']=Lang('VALID_OPERATION');
		}
		$this->showMsg($result);
	}
	public function restore()
	{
		$file_name = empty($_GET['file_name']) ? '': trim($_GET['file_name']);
		$result=Model('sys')->import($file_name);
		$this->showMsg($result);
	}
	public function backup()
	{
	
		$result=Model('sys')->backup();
		$this->showMsg($result);
	
	
	}
	public function saveSetting()
	{
		$info['site_name']=isset($_POST['site_name'])?$_POST['site_name']:'';
		$info['domain']=isset($_POST['domain'])?$_POST['domain']:'';
		$info['site_keyword']=isset($_POST['site_keyword'])?$_POST['site_keyword']:''; 
		$info['site_abs']=isset($_POST['site_abs'])?$_POST['site_abs']:'';
		$info['site_des']=isset($_POST['site_des'])?$_POST['site_des']:'';
		$info['icp']=isset($_POST['icp'])?$_POST['icp']:'';
		$info['site_logo']=isset($_POST['site_logo'])?$_POST['site_logo']:'';
		$info['site_line']=isset($_POST['site_line'])?$_POST['site_line']:'';
		$info['site_qq']=isset($_POST['site_qq'])?$_POST['site_qq']:'';
		$info['site_time']=isset($_POST['site_time'])?$_POST['site_time']:'';
		$info['site_address']=isset($_POST['site_address'])?$_POST['site_address']:'';
		$info['copyright']=isset($_POST['copyright'])?$_POST['copyright']:'';
		/* $info['wap_support']=isset($_POST['wap_support'])?intval($_POST['wap_support']):'';
		$info['home_tpl']=isset($_POST['home_tpl'])?$_POST['home_tpl']:'default'; */
		$result=array('error'=>1,'content'=>'');
		if(Model('sys')->saveSetting($info))
		{
			$result['error']=0;
			$result['content']=Lang('VALID_OPERATION');
		}
		else
		{
			$result['content']=Lang('INVALID_OPERATION');
		}
		$this->showMsg($result);
	}
	private function writeStatic()
	{
		
	}
	private function getTpl()
	{
		$path=HOME_PATH.'/View';
		$real_list = array();
		$folder = opendir($path);
		
		while ($file = readdir($folder))
		{
		
			if($file == '.' || $file == '..')
			{
				continue;
			}elseif(is_dir($path.'/'.$file))
			{
				$tpl_list[] = $file;
			}
		}
		
		return $tpl_list;
	}
	
}